
$(function () {
		
	var oXArr = [];
    var oYArr = [];
    var rightArr = [];
    var leftArr = [];
    var topArr = [];
    var downArr = [];

    var movel = {
    	rightMoveL: '',
    	leftMoveL: '',
    	downMoveL: '',
    	upMoveL: '',
    }

    var mouse = $('.circle-box');
    var init_xy 
    init_xy = mouse.offset()
		console.log(init_xy)
    var xy_i = setInterval(function () {
		init_xy = mouse.offset()
		// console.log(init_xy)
	}, 100)

    $("body").mousemove(function(e) {

        var obxX = e.pageX;
        var obxY = e.pageY;
        oXArr.unshift(obxX);
        oYArr.unshift(obxY);
        oXArr.splice(2, 1);
        oYArr.splice(2, 1);

        // tfo();
        function tfo() {

            if (oXArr[0] > oXArr[1]) {
                // console.log("向右");
                leftArr = [];
                rightArr.push(obxX);
                movel.rightMoveL = Math.abs(rightArr[rightArr.length - 1] - rightArr[0]);
                // console.log(movel.rightMoveL)

                return true;
            } else {
                // console.log("向左");
                rightArr = [];
                leftArr.push(obxX);
                movel.leftMoveL = Math.abs(leftArr[leftArr.length - 1] - leftArr[0]);
                // console.log(movel.leftMoveL)

                return false;
            }

        }
        // tfw();
        function tfw() {
            if (oYArr[0] > oYArr[1]) {
                // console.log("向下");
                topArr = [];
                downArr.push(obxY);
                movel.downMoveL = Math.abs(downArr[downArr.length - 1] - downArr[0]);

                return true;
            } else {
                // console.log("向上");
                downArr = [];
                topArr.push(obxY);
                movel.upMoveL = Math.abs(topArr[topArr.length - 1] - topArr[0]);

                // mouse.css('top', init_xy.top - movel.upMoveL / 50 + 'px')

                return false;
            }
        }


        if (tfo() && tfw()) {
            //右下
            // console.log("右下");

            mouse.addClass('right-down')
            setTimeout(function () {
            	mouse.removeClass('right-down')
            }, 2000)

            return false

        } else if (tfo() && !tfw()) {
            //右上

            mouse.addClass('right-up')
            setTimeout(function () {
            	mouse.removeClass('right-up')
            }, 2000)

            return false
        } else if (!tfo() && tfw()) {
            //左下
            mouse.addClass('left-down')
            setTimeout(function () {
            	mouse.removeClass('left-down')
            }, 2000)

            return false

        } else if (!tfo() && !tfw()) {
            //左上

            mouse.addClass('left-up')
            setTimeout(function () {
            	mouse.removeClass('left-up')
            }, 2000)

            return false
        }
    });
})